# -*- encoding: utf-8 -*-
##############################################################################
##############################################################################

from odoo import models, fields, api
from odoo.tools.translate import _
from odoo.exceptions import ValidationError
from odoo.tools.float_utils import float_round


class stock_picking(models.Model):
    _inherit = 'stock.picking'

    @api.model
    def _prepare_values_extra_move(self, op, product, remaining_qty):
        res = super(stock_picking, self)._prepare_values_extra_move(op, product, remaining_qty)
        if op.linked_move_operation_ids:
            res['price_unit'] = op.linked_move_operation_ids[0].move_id.price_unit
        else:
            res['price_unit'] = op.product_id.standard_price
        return res
        # """
        # Creates an extra move when there is no corresponding original move to be copied
        # """
        # Uom = self.env["product.uom"]
        # uom_id = product.uom_id.id
        # qty = remaining_qty
        # if op.product_id and op.product_uom_id and op.product_uom_id.id != product.uom_id.id:
        #     if op.product_uom_id.factor > product.uom_id.factor:  # If the pack operation's is a smaller unit
        #         uom_id = op.product_uom_id.id
        #         # HALF-UP rounding as only rounding errors will be because of propagation of error from default UoM
        #         qty = product.uom_id._compute_quantity(remaining_qty, op.product_uom_id, rounding_method='HALF-UP')
        # picking = op.picking_id
        # ref = product.default_code
        # name = '[' + ref + ']' + ' ' + product.name if ref else product.name
        # proc_id = False
        # for m in op.linked_move_operation_ids:
        #     if m.move_id.procurement_id:
        #         proc_id = m.move_id.procurement_id.id
        #         break
        # return {
        #     'picking_id': picking.id,
        #     'location_id': picking.location_id.id,
        #     'location_dest_id': picking.location_dest_id.id,
        #     'product_id': product.id,
        #     'procurement_id': proc_id,
        #     'product_uom': uom_id,
        #     'product_uom_qty': qty,
        #     'name': _('Extra Move: ') + name,
        #     'state': 'draft',
        #     'restrict_partner_id': op.owner_id.id,
        #     'group_id': picking.group_id.id,
        # }
